package com.youku.core.model
{
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.core.model.vo.PlayListData;
   import com.youku.interfaces.IRootData;
   import flash.net.URLLoader;
   import flash.utils.Timer;
   import com.youku.interfaces.IFSOProxy;
   import com.youku.GlobalService;
   import com.youku.GlobalServiceKeys;
   import com.youku.PlayerConfig;
   import flash.events.TimerEvent;
   import flash.events.Event;
   import flash.events.IOErrorEvent;
   import flash.events.SecurityErrorEvent;
   import com.youku.events.CoreFacadeEvent;
   import com.youku.data.PlayerConstant;
   import flash.net.URLVariables;
   import flash.net.URLRequest;
   import flash.net.URLRequestMethod;
   import com.youku.events.ReportEvent;
   import com.youku.data.LoadTimeData;
   import com.youkuet.RandomProxy;
   import com.adobe.json.JSON;
   import flash.utils.Dictionary;
   import com.youku.core.model.vo.VideoSegmentData;
   import com.youkuet.HashCash;
   import com.youku.utils.PlayListUtil;
   import com.youku.utils.MathUtil;
   import com.youku.core.model.vo.FolderData;
   import com.youku.core.model.vo.UserData;
   import com.youku.core.model.vo.ControllerData;
   import com.youku.core.model.vo.VerifyUserData;
   import com.youku.core.model.vo.ShowData;
   import com.youku.core.model.vo.ProgramListData;
   import com.youku.interfaces.IProgramData;
   import com.youku.core.model.vo.ProgramData;
   import com.youku.core.model.vo.TrialData;
   import com.youku.data.CaptionData;
   import com.youku.data.ThreeDData;
   import com.youku.core.model.vo.DVDData;
   import com.youku.core.model.vo.InsertPointData;
   
   public class PlayListProxy extends Object
   {
      
      public function PlayListProxy(param1:IPlayerProxy) {
         super();
         this._playerProxy = param1;
         this._playListData = new PlayListData();
      }
      
      private var _playerProxy:IPlayerProxy;
      
      private var _playListData:PlayListData;
      
      private var _rootData:IRootData;
      
      private var _othervid:String;
      
      private var _loader:URLLoader;
      
      private var _retryCount:Number;
      
      private var _loaderTimer:Timer;
      
      private var _timeOut:Number = 15000.0;
      
      private function get fsoProxy() : IFSOProxy {
         return GlobalService.getService(GlobalServiceKeys.FSO_PROXY) as IFSOProxy;
      }
      
      public function init(param1:String = null) : void {
         this._rootData = PlayerConfig.rootData;
         this._othervid = param1;
         this._loaderTimer = new Timer(this._timeOut);
         this._loaderTimer.addEventListener(TimerEvent.TIMER,this.onLoadTimeOut);
         this._retryCount = 3;
         this.requestPlaylist(this._retryCount);
      }
      
      public function close() : void {
         this._loader.removeEventListener(Event.COMPLETE,this.onLoaderComplete);
         this._loader.removeEventListener(IOErrorEvent.IO_ERROR,this.onLoaderIOError);
         this._loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onLoaderSecurityError);
         try
         {
            this._loader.close();
         }
         catch(e:Error)
         {
         }
         this._loaderTimer.stop();
      }
      
      private function playFromURL() : void {
         this._playListData = new PlayListData();
         this._playListData.singlePlayURL = this._rootData.playURL;
         this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOADED,this._playListData));
      }
      
      private function getServerDomain() : String {
         var baseurl:String = null;
         var domain:String = PlayerConstant.PLAYLIST_NORMAL_SITE;
         if(PlayerConfig.specialType == PlayerConstant.SPECIAL_TYPE_SHENHE || PlayerConfig.specialType == PlayerConstant.SPECIAL_TYPE_JIETU)
         {
            baseurl = this._rootData.baseURL;
            try
            {
               domain = baseurl.split("/")[2];
            }
            catch(e:Error)
            {
               domain = PlayerConstant.PLAYLIST_NORMAL_SITE;
            }
            if(this._rootData.om)
            {
               domain = PlayerConstant.PLAYLIST_NORMAL_SITE;
            }
         }
         return domain;
      }
      
      private function requestPlaylist(param1:Number = 0) : void {
         var _loc2_:Date = new Date();
         var _loc3_:String = _loc2_.toString();
         var _loc4_:Number = _loc3_.indexOf("GMT");
         var _loc5_:String = _loc3_.substr(_loc4_ + 3,3);
         var _loc6_:String = this._rootData.videoId;
         if(!(this._othervid == null) && !(this._othervid == ""))
         {
            _loc6_ = _loc6_ + ("," + this._othervid);
         }
         var _loc7_:String = this.getServerDomain();
         var _loc8_:* = "http://" + _loc7_ + "/player/getPlayList";
         _loc8_ = _loc8_ + ("/VideoIDS/" + _loc6_);
         _loc8_ = _loc8_ + ("/timezone/" + _loc5_);
         _loc8_ = _loc8_ + ("/version/" + this._rootData.version);
         _loc8_ = _loc8_ + ("/source/" + this._rootData.source);
         if(!(this._rootData.type == null) && !(this._rootData.type == ""))
         {
            _loc8_ = _loc8_ + ("/Type/" + this._rootData.type);
         }
         if(this._rootData.type == "Folder")
         {
            _loc8_ = _loc8_ + ("/Fid/" + this._rootData.fid + "/Pt/" + this._rootData.pt);
            if(this._rootData.ob)
            {
               _loc8_ = _loc8_ + ("/Ob/" + this._rootData.ob);
            }
         }
         if(this._rootData.pf)
         {
            _loc8_ = _loc8_ + ("/Pf/" + this._rootData.pf);
         }
         if(PlayerConfig.isTudouPlayer)
         {
            _loc8_ = _loc8_ + ("/Sc/" + 2);
         }
         var _loc9_:URLVariables = new URLVariables();
         _loc9_.n = 3;
         _loc9_.ran = int(Math.random() * 9999);
         if(this._rootData.isRedirect == 0)
         {
            _loc9_.isRedirect = 0;
         }
         _loc9_.password = escape(this._rootData.passwords == null?"":this._rootData.passwords);
         if(!(this._rootData.passwords == null) && !(this._rootData.partnerId == null) && PlayerConfig.partnerData.status == 1 && PlayerConfig.partnerData.passless == 1)
         {
            _loc9_.client_id = escape(this._rootData.partnerId);
         }
         if((this._rootData.extstring) && !(this._rootData.extstring == ""))
         {
            _loc9_.extstring = this._rootData.extstring;
         }
         if((this._rootData.yktk) && !(this._rootData.yktk == ""))
         {
            _loc9_.yktk = this._rootData.yktk;
         }
         _loc9_.ctype = PlayerConstant.CTYPE;
         _loc9_.ev = PlayerConstant.EV;
         var _loc10_:URLRequest = new URLRequest();
         _loc10_.url = _loc8_;
         _loc10_.data = _loc9_;
         _loc10_.method = URLRequestMethod.GET;
         this._loader = new URLLoader();
         this._loader.addEventListener(Event.COMPLETE,this.onLoaderComplete);
         this._loader.addEventListener(IOErrorEvent.IO_ERROR,this.onLoaderIOError);
         this._loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onLoaderSecurityError);
         this._loader.load(_loc10_);
         this._loaderTimer.reset();
         this._loaderTimer.start();
      }
      
      private function onLoaderSecurityError(param1:SecurityErrorEvent) : void {
         this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.LOAD_TIME_REPORT,
            {
               "isError":true,
               "type":LoadTimeData.TYPE_GETPLAYLIST,
               "errorCode":LoadTimeData.ERROR_CODE_SECURITY
            }));
         this.onLoaderError(null);
      }
      
      private function onLoaderIOError(param1:IOErrorEvent) : void {
         this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.LOAD_TIME_REPORT,
            {
               "isError":true,
               "type":LoadTimeData.TYPE_GETPLAYLIST,
               "errorCode":LoadTimeData.ERROR_CODE_IO
            }));
         this.onLoaderError(null);
      }
      
      private function onLoaderComplete(param1:Event) : void {
         this._loaderTimer.stop();
         this._retryCount--;
         var _loc2_:String = URLLoader(param1.currentTarget).data;
         this.parseData(_loc2_);
      }
      
      private function onLoaderError(param1:Event) : void {
         this._loaderTimer.stop();
         this._retryCount--;
         if(this._retryCount < 1)
         {
            this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_FATAL_ERROR,{"type":"noConnect"}));
         }
         else
         {
            this.requestPlaylist(this._retryCount);
         }
      }
      
      private function onLoadTimeOut(param1:TimerEvent) : void {
         var e:TimerEvent = param1;
         this._loaderTimer.stop();
         try
         {
            this._loader.close();
         }
         catch(e:Error)
         {
         }
         this._playerProxy.dispatchEvent(new ReportEvent(ReportEvent.LOAD_TIME_REPORT,
            {
               "isError":true,
               "type":LoadTimeData.TYPE_GETPLAYLIST,
               "errorCode":LoadTimeData.ERROR_CODE_TIMEOUT
            }));
         this.onLoaderError(null);
      }
      
      private function parseData(param1:String) : void {
         var k:String = null;
         var randProxy:RandomProxy = null;
         var dvdPlaylist:PlayListData = null;
         var di:int = 0;
         var jstr:String = param1;
         if(jstr == null || jstr == "")
         {
            this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_ERROR));
            if(this._retryCount < 1)
            {
               this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_FATAL_ERROR,{"type":"noData"}));
            }
            else
            {
               this.requestPlaylist(this._retryCount);
            }
            return;
         }
         var obj:Object = null;
         try
         {
            obj = com.adobe.json.JSON.decode(jstr);
         }
         catch(e:Error)
         {
            obj = new Object();
         }
         if(obj.data == null || obj.data.length <= 0)
         {
            this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_NO_DATA));
            this._retryCount--;
            if(this._retryCount < 1)
            {
               this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOAD_FATAL_ERROR,{"type":"noData"}));
            }
            else
            {
               this.requestPlaylist(this._retryCount);
            }
            return;
         }
         this._playListData.folder = this.parseFolderData(obj.folder);
         this._playListData.user = this.parseUserData(obj.user);
         this._playListData.controller = this.parseControllerData(obj.controller);
         this._playListData.verifyUser = this.parseVerifyUserData(obj.verify_user);
         var data:Object = obj.data[0];
         this.parseMainData(this._playListData,data);
         if(!(this._othervid == null) && !(this._othervid == ""))
         {
            dvdPlaylist = new PlayListData();
            data = obj.data[1];
            this.parseMainData(dvdPlaylist,data);
            this._playListData.sid = PlayerConfig.dvdSID;
            this._playListData.tk = PlayerConfig.dvdtoken;
            this._playListData.oip = PlayerConfig.dvdoip;
            this._playListData.key1 = dvdPlaylist.key1;
            this._playListData.key2 = dvdPlaylist.key2;
            this._playListData.seed = dvdPlaylist.seed;
            this._playListData.seconds = dvdPlaylist.seconds;
            this._playListData.totalTime = dvdPlaylist.totalTime;
            this._playListData.videoSegmentsDic = dvdPlaylist.videoSegmentsDic;
            this._playListData.streamSizes = dvdPlaylist.streamSizes;
            this._playListData.streamFileIds = dvdPlaylist.streamFileIds;
            this._playListData.streamTypes = dvdPlaylist.streamTypes;
            this._playListData.typeArr = dvdPlaylist.typeArr;
            this._playListData.watermarks = dvdPlaylist.watermarks;
            this._playListData.error = dvdPlaylist.error;
            this._playListData.errorlink = dvdPlaylist.errorlink;
            this._playListData.rtmp = dvdPlaylist.rtmp;
            if(this._playListData.dvdinfo.notsharing == 1)
            {
               this._playListData.dvdinfo.headPostion = dvdPlaylist.dvdinfo.headPostion;
               this._playListData.dvdinfo.tailPostion = dvdPlaylist.dvdinfo.tailPostion;
               this._playListData.dvdinfo.insertPoints = dvdPlaylist.dvdinfo.insertPoints;
               this._playListData.threeD = dvdPlaylist.threeD;
               this._playListData.caption = dvdPlaylist.caption;
            }
            this._playListData.currentLang = "";
            this._playListData.currentLangID = "0";
            if((this._playListData.dvdinfo) && this._playListData.dvdinfo.audioLangs.length > 1)
            {
               di = 0;
               while(di < this._playListData.dvdinfo.audioLangs.length)
               {
                  if(dvdPlaylist.vidEncoded == this._playListData.dvdinfo.audioLangs[di].vid || dvdPlaylist.videoId == this._playListData.dvdinfo.audioLangs[di].vid)
                  {
                     this._playListData.currentLang = this._playListData.dvdinfo.audioLangs[di].lang;
                     this._playListData.currentLangID = this._playListData.dvdinfo.audioLangs[di].langid;
                     this._playListData.currentLangVid = this._playListData.dvdinfo.audioLangs[di].vid;
                  }
                  di++;
               }
            }
         }
         this._playListData.fileType = this.getInitialFileType();
         this._playListData.resetTimeArr();
         var streamFid:String = "";
         for(k in data.streamfileids)
         {
            if(k == this._playListData.fileType)
            {
               streamFid = data.streamfileids[k];
               break;
            }
         }
         randProxy = new RandomProxy(this._playListData.seed);
         this._playListData.currentFileId = randProxy.cg_fun(streamFid);
         PlayerConfig.isRTMP = this._playListData.rtmp;
         if(this._playListData.caption)
         {
            this._playListData.caption.videoID = this._playListData.videoId;
         }
         this._playerProxy.dispatchEvent(new CoreFacadeEvent(CoreFacadeEvent.PLAY_LIST_DATA_LOADED,this._playListData));
      }
      
      private function parseMainData(param1:PlayListData, param2:Object) : void {
         var _loc5_:String = null;
         var _loc9_:String = null;
         var _loc10_:String = null;
         var _loc11_:Object = null;
         var _loc12_:String = null;
         var _loc13_:Array = null;
         var _loc14_:RandomProxy = null;
         var _loc15_:Dictionary = null;
         var _loc16_:String = null;
         var _loc17_:String = null;
         var _loc18_:Array = null;
         var _loc19_:* = 0;
         var _loc20_:String = null;
         var _loc21_:Array = null;
         var _loc22_:String = null;
         var _loc23_:Object = null;
         var _loc24_:VideoSegmentData = null;
         if(param1 == null || param2 == null)
         {
            return;
         }
         if(param2.interact)
         {
            param1.interact = param2.interact;
         }
         else
         {
            param1.interact = false;
         }
         param1.drm = param2.drm;
         param1.rtmp = param2.rtmp;
         param1.ct = param2.ct;
         param1.show = this.parseShowData(param2.show);
         param1.programList = this.parseProgramListData(param2.list,param2.list_pre,param2.list_next);
         param1.dvdinfo = this.parseDVDData(param2.dvd);
         param1.trial = this.pareseTrialData(param2.trial);
         param1.caption = this.parseCaptionData(param2.dvd);
         param1.threeD = this.parseThreeDData(param2.dvd);
         param1.tt = param2.tt;
         param1.ct = param2.ct;
         param1.cs = param2.cs;
         param1.logo = param2.logo;
         param1.seed = Number(param2.seed);
         param1.tags = param2.tags;
         param1.categories = param2.categories;
         param1.videoId = String(param2.videoid);
         param1.vidEncoded = param2.vidEncoded;
         param1.userName = param2.username;
         param1.userId = param2.userid;
         param1.title = unescape(param2.title);
         param1.key1 = (Number("0x" + param2.key1) ^ Number("0xA55AA5A5")).toString(16);
         param1.key2 = param2.key2;
         param1.seconds = Number(param2.seconds);
         if(param2.sourceVid != null)
         {
            param1.sourceVid = Number(param2.sourceVid);
         }
         param1.streamFileIds = param2.streamfileids;
         param1.segs = param2.segs;
         param1.streamSizes = param2.streamsizes;
         param1.streamTypes = param2.streamtypes;
         param1.error = param2.error;
         param1.errorlink = param2.link;
         param1.up = param2.up;
         param1.down = param2.down;
         if(param2.lastpoint)
         {
            param1.lastpoint = Number(param2.lastpoint);
         }
         param1.token = param2.ts?param2.ts:"";
         var _loc3_:HashCash = new HashCash();
         param1.hashcash = _loc3_.getHashCash(param1.token + "o");
         param1.tokenup = param2.tsup?param2.tsup:"";
         param1.hashcashup = _loc3_.getHashCash(param1.tokenup);
         param1.oip = param2.ip;
         if(param2.ep)
         {
            _loc17_ = PlayListUtil.getInstance().getSize(param2.ep);
            _loc18_ = _loc17_.split("_");
            param1.sid = _loc18_[0];
            param1.tk = _loc18_[1];
         }
         param1.currentLang = "";
         if((param1.dvdinfo) && param1.dvdinfo.audioLangs.length > 1)
         {
            _loc19_ = 0;
            while(_loc19_ < param1.dvdinfo.audioLangs.length)
            {
               if(param1.vidEncoded == param1.dvdinfo.audioLangs[_loc19_].vid || param1.videoId == param1.dvdinfo.audioLangs[_loc19_].vid)
               {
                  param1.currentLang = param1.dvdinfo.audioLangs[_loc19_].lang;
                  param1.currentLangID = param1.dvdinfo.audioLangs[_loc19_].langid;
               }
               _loc19_++;
            }
         }
         var _loc4_:Array = [];
         for(_loc5_ in param2.streamfileids)
         {
            if(this.isValidType(_loc5_))
            {
               _loc4_.push(_loc5_);
            }
         }
         param1.typeArr = _loc4_;
         this._playListData.fileType = _loc4_[0];
         if(_loc4_.length > 1)
         {
         }
         var _loc6_:Number = 0;
         var _loc7_:Number = Number.MAX_VALUE;
         var _loc8_:Object = param2.segs;
         for(_loc9_ in _loc8_)
         {
            if(_loc9_ == "flv" || _loc9_ == "mp4" || _loc9_ == "flvhd" || _loc9_ == "hd2" || _loc9_ == "hd3")
            {
               _loc6_ = 0;
               for(_loc20_ in _loc8_[_loc9_])
               {
                  _loc6_ = _loc6_ + Number(_loc8_[_loc9_][_loc20_].seconds);
               }
               if(_loc6_ < _loc7_)
               {
                  _loc7_ = _loc6_;
               }
            }
         }
         param1.totalTime = _loc7_;
         _loc10_ = "";
         _loc11_ = param2.streamfileids;
         for(_loc12_ in _loc11_)
         {
            if(_loc12_ == param1.fileType)
            {
               _loc10_ = _loc11_[_loc12_];
               break;
            }
         }
         _loc13_ = [];
         _loc14_ = new RandomProxy(param1.seed);
         _loc15_ = new Dictionary();
         for(_loc16_ in param2.segs)
         {
            if(this.isValidType(_loc16_))
            {
               _loc21_ = [];
               for(_loc22_ in param2.segs[_loc16_])
               {
                  _loc23_ = param2.segs[_loc16_][_loc22_];
                  _loc24_ = new VideoSegmentData();
                  _loc24_.no = _loc23_.no;
                  _loc24_.size = _loc23_.size;
                  _loc24_.seconds = _loc23_.seconds;
                  if(_loc23_.k)
                  {
                     _loc24_.key = _loc23_.k;
                  }
                  _loc24_.fileId = this.getFileId(_loc11_,_loc16_,int(_loc22_),_loc14_);
                  _loc24_.type = _loc16_;
                  _loc21_.push(_loc24_);
               }
               _loc15_[_loc16_] = _loc21_;
            }
         }
         param1.videoSegmentsDic = _loc15_;
         param1.watermarks = param2.streamlogos;
         if(param2.hasOwnProperty("paike"))
         {
            param1.paike = param2.paike;
         }
         else
         {
            param1.paike = false;
         }
         if(param2.hasOwnProperty("share"))
         {
            param1.share = param2.share;
         }
         else
         {
            param1.share = false;
         }
         if(param2.hasOwnProperty("share_type"))
         {
            param1.share_type = param2.share_type;
         }
         param1.previews = this.parsePreviews(param2.preview);
      }
      
      private function getInitialFileType() : String {
         var _loc1_:String = this.fsoProxy.getDefaultQuality();
         var _loc2_:* = "";
         if(!(this._rootData.firstQuality == null) && !(this._rootData.firstQuality == ""))
         {
            _loc1_ = this._rootData.firstQuality;
         }
         var _loc3_:Array = this._playListData.typeArr;
         if(_loc1_ == PlayerConstant.QUALITY_AUTO)
         {
            _loc2_ = this.getControllerStreamModeType(this._playListData.controller.stream_mode);
            _loc2_ = this.getDownloadSpeedRestrict(_loc2_);
         }
         else if(_loc1_ == PlayerConstant.QUALITY_1080P)
         {
            if(this.has1080PQuality(_loc3_))
            {
               _loc2_ = "hd3";
            }
            else if(!this.has1080PQuality(_loc3_) && (this.hasHighQuality(_loc3_)))
            {
               _loc2_ = "hd2";
            }
            else if(!this.has1080PQuality(_loc3_) && !this.hasHighQuality(_loc3_) && (this.hasMiddleQuality(_loc3_)))
            {
               _loc2_ = "mp4";
            }
            else
            {
               _loc2_ = "flv";
            }
            
            
         }
         else if(_loc1_ == PlayerConstant.QUALITY_HIGH)
         {
            if(this.hasHighQuality(_loc3_))
            {
               _loc2_ = "hd2";
            }
            else if(!this.hasHighQuality(_loc3_) && (this.hasMiddleQuality(_loc3_)))
            {
               _loc2_ = "mp4";
            }
            else
            {
               _loc2_ = "flv";
            }
            
         }
         else if(_loc1_ == PlayerConstant.QUALITY_MID)
         {
            if(this.hasMiddleQuality(_loc3_))
            {
               _loc2_ = "mp4";
            }
            else
            {
               _loc2_ = "flv";
            }
         }
         else if(_loc1_ == PlayerConstant.QUALITY_LOW)
         {
            _loc2_ = "flv";
         }
         
         
         
         
         if(PlayerConfig.tempQuality != "")
         {
            _loc2_ = PlayerConfig.tempQuality;
            if(_loc2_ == "auto")
            {
               _loc2_ = this.getControllerStreamModeType(this._playListData.controller.stream_mode);
               _loc2_ = this.getDownloadSpeedRestrict(_loc2_);
            }
            if(_loc2_ == "hd3")
            {
               if(this.has1080PQuality(_loc3_))
               {
                  _loc2_ = "hd3";
               }
               else if(!this.has1080PQuality(_loc3_) && (this.hasHighQuality(_loc3_)))
               {
                  _loc2_ = "hd2";
               }
               else if(!this.has1080PQuality(_loc3_) && !this.hasHighQuality(_loc3_) && (this.hasMiddleQuality(_loc3_)))
               {
                  _loc2_ = "mp4";
               }
               else
               {
                  _loc2_ = "flv";
               }
               
               
            }
            else if(_loc2_ == "hd2")
            {
               if(this.hasHighQuality(_loc3_))
               {
                  _loc2_ = "hd2";
               }
               else if(!this.hasHighQuality(_loc3_) && (this.hasMiddleQuality(_loc3_)))
               {
                  _loc2_ = "mp4";
               }
               else
               {
                  _loc2_ = "flv";
               }
               
            }
            else if(_loc2_ == "mp4")
            {
               if(this.hasMiddleQuality(_loc3_))
               {
                  _loc2_ = "mp4";
               }
               else
               {
                  _loc2_ = "flv";
               }
            }
            else
            {
               _loc2_ = "flv";
            }
            
            
         }
         if(_loc2_ == "mp4" && !this.hasMiddleQuality(_loc3_))
         {
            _loc2_ = "flv";
         }
         if(_loc2_ == "flv" && (this.hasFLVHD(_loc3_)))
         {
            _loc2_ = "flvhd";
         }
         this.clearDownloadSpeeds();
         return _loc2_;
      }
      
      private function hasFLVHD(param1:Array) : Boolean {
         if(param1 == null)
         {
            return false;
         }
         var _loc2_:* = 0;
         while(_loc2_ < param1.length)
         {
            if(param1[_loc2_] == "flvhd")
            {
               return true;
            }
            _loc2_++;
         }
         return false;
      }
      
      private function has1080PQuality(param1:Array) : Boolean {
         if(param1 == null)
         {
            return false;
         }
         if(this._playListData.controller.hd3_enabled == false)
         {
            return false;
         }
         var _loc2_:* = 0;
         while(_loc2_ < param1.length)
         {
            if(param1[_loc2_] == "hd3")
            {
               return true;
            }
            _loc2_++;
         }
         return false;
      }
      
      private function hasHighQuality(param1:Array) : Boolean {
         if(param1 == null)
         {
            return false;
         }
         var _loc2_:* = 0;
         while(_loc2_ < param1.length)
         {
            if(param1[_loc2_] == "hd2")
            {
               return true;
            }
            _loc2_++;
         }
         return false;
      }
      
      private function hasMiddleQuality(param1:Array) : Boolean {
         if(param1 == null)
         {
            return false;
         }
         var _loc2_:* = 0;
         while(_loc2_ < param1.length)
         {
            if(param1[_loc2_] == "mp4")
            {
               return true;
            }
            _loc2_++;
         }
         return false;
      }
      
      private function getControllerStreamModeType(param1:int) : String {
         if(param1 == 1)
         {
            return "flv";
         }
         if(param1 == 2)
         {
            return "mp4";
         }
         if(param1 == 3)
         {
            return "hd2";
         }
         return "flv";
      }
      
      private function getDownloadSpeedRestrict(param1:String) : String {
         var _loc2_:Array = this.fsoProxy.getDownloadSpeed(this._playListData.controller.area_dma_code);
         var _loc3_:Date = new Date();
         var _loc4_:Date = new Date();
         var _loc5_:Array = [];
         var _loc6_:* = 0;
         while(_loc6_ < _loc2_.length)
         {
            _loc4_.setTime(_loc2_[_loc6_].time);
            if(_loc3_.hours < 18 && _loc4_.hours < 18 || _loc3_.hours >= 18 && _loc4_.hours >= 18)
            {
               _loc5_.push(_loc2_[_loc6_]);
            }
            _loc6_++;
         }
         var _loc7_:Array = _loc5_.sort(this.sortOnTime,Array.DESCENDING);
         _loc7_ = _loc7_.slice(0,15);
         var _loc8_:Array = _loc7_.slice(0,3);
         var _loc9_:Array = [];
         _loc6_ = 0;
         while(_loc6_ < _loc8_.length)
         {
            if(_loc8_[_loc6_].s > 0)
            {
               _loc9_.push(_loc8_[_loc6_].s);
            }
            _loc6_++;
         }
         var _loc10_:Number = MathUtil.average(_loc9_);
         if(_loc8_.length < 3)
         {
            return param1;
         }
         var _loc11_:* = "mp4";
         if(_loc10_ < 600 * 1024 / 8)
         {
            _loc11_ = "flv";
         }
         var _loc12_:String = param1;
         switch(param1)
         {
            case "flv":
               _loc12_ = "flv";
               break;
            case "mp4":
               if(_loc11_ == "flv")
               {
                  _loc12_ = "flv";
               }
               else if(_loc11_ == "mp4")
               {
                  _loc12_ = "mp4";
               }
               
               break;
         }
         return _loc12_;
      }
      
      private function clearDownloadSpeeds() : void {
         var _loc1_:Array = this.fsoProxy.getDownloadSpeed(this._playListData.controller.area_dma_code);
         if(_loc1_ == null)
         {
            return;
         }
         var _loc2_:Array = _loc1_.sort(this.sortOnTime,Array.DESCENDING);
         var _loc3_:* = 0;
         while(_loc3_ < _loc1_.length)
         {
            _loc3_++;
         }
         _loc2_ = _loc2_.slice(0,30);
         this.fsoProxy.saveDownloadSpeeds(this._playListData.controller.area_dma_code,_loc2_);
      }
      
      private function sortOnTime(param1:Object, param2:Object) : Number {
         if(param1.time > param2.time)
         {
            return 1;
         }
         if(param1.time < param2.time)
         {
            return -1;
         }
         return 0;
      }
      
      private function getFileId(param1:Object, param2:String, param3:int, param4:RandomProxy) : String {
         var _loc6_:String = null;
         var _loc5_:* = "";
         for(_loc6_ in param1)
         {
            if(_loc6_ == param2)
            {
               _loc5_ = param1[_loc6_];
               break;
            }
         }
         if(_loc5_ == "")
         {
            return "";
         }
         var _loc7_:* = "";
         var _loc8_:String = param4.cg_fun(_loc5_);
         var _loc9_:String = _loc8_.slice(0,8);
         var _loc10_:int = int(param3);
         var _loc11_:String = _loc10_.toString(16);
         if(_loc11_.length == 1)
         {
            _loc11_ = "0" + _loc11_;
         }
         _loc11_ = _loc11_.toUpperCase();
         var _loc12_:String = _loc8_.slice(10,_loc8_.length);
         _loc7_ = _loc9_ + _loc11_ + _loc12_;
         return _loc7_;
      }
      
      private function isValidType(param1:String) : Boolean {
         if(param1 == "flv" || param1 == "mp4" || param1 == "flvhd" || param1 == "hd2" || param1 == "hd3")
         {
            return true;
         }
         return false;
      }
      
      private function parseFolderData(param1:Object) : FolderData {
         if(param1 == null)
         {
            return null;
         }
         var _loc2_:FolderData = new FolderData();
         if(param1.hasOwnProperty("total"))
         {
            _loc2_.total = Number(param1.total);
         }
         if(param1.hasOwnProperty("size"))
         {
            _loc2_.size = Number(param1.size);
         }
         if(param1.hasOwnProperty("page"))
         {
            _loc2_.page = Number(param1.page);
         }
         if(param1.hasOwnProperty("folderId"))
         {
            _loc2_.folderId = Number(param1.folderId);
         }
         if(param1.hasOwnProperty("ownerId"))
         {
            _loc2_.ownerId = Number(param1.ownerId);
         }
         if(param1.hasOwnProperty("totalPage"))
         {
            _loc2_.totalPage = Number(param1.totalPage);
         }
         return _loc2_;
      }
      
      private function parseUserData(param1:Object) : UserData {
         if(param1 == null)
         {
            return new UserData();
         }
         var _loc2_:UserData = new UserData();
         if(param1.hasOwnProperty("id"))
         {
            _loc2_.userID = param1.id;
         }
         if(param1.hasOwnProperty("vip"))
         {
            _loc2_.vip = param1.vip;
         }
         if(param1.hasOwnProperty("vipnotes"))
         {
            _loc2_.vipnotes = param1.vipnotes;
         }
         if(param1.hasOwnProperty("acc_support"))
         {
            _loc2_.acc_support = param1.acc_support;
         }
         if(param1.hasOwnProperty("acc_open"))
         {
            _loc2_.acc_open = param1.acc_open;
         }
         return _loc2_;
      }
      
      private function parseControllerData(param1:Object) : ControllerData {
         if(param1 == null)
         {
            return new ControllerData();
         }
         var _loc2_:ControllerData = new ControllerData();
         if(param1.hasOwnProperty("search_count"))
         {
            _loc2_.search_count = param1.search_count;
         }
         if(param1.hasOwnProperty("stream_mode"))
         {
            _loc2_.stream_mode = param1.stream_mode;
         }
         if(param1.hasOwnProperty("share_disabled"))
         {
            _loc2_.share_disabled = param1.share_disabled;
         }
         if(param1.hasOwnProperty("download_disabled"))
         {
            _loc2_.download_disabled = param1.download_disabled;
         }
         if(param1.hasOwnProperty("video_capture"))
         {
            _loc2_.video_capture = param1.video_capture;
         }
         if(param1.hasOwnProperty("continuous"))
         {
            _loc2_.continuous = param1.continuous;
         }
         if(param1.hasOwnProperty("area_code"))
         {
            _loc2_.area_code = param1.area_code;
         }
         if(param1.hasOwnProperty("dma_code"))
         {
            _loc2_.dma_code = param1.dma_code;
         }
         if(param1.hasOwnProperty("playmode"))
         {
            _loc2_.playmode = param1.playmode;
         }
         if(param1.hasOwnProperty("circle"))
         {
            _loc2_.circle = param1.circle;
         }
         if(param1.hasOwnProperty("tsflag"))
         {
            _loc2_.tsflag = param1.tsflag;
         }
         if(param1.hasOwnProperty("hd3_enabled"))
         {
            _loc2_.hd3_enabled = param1.hd3_enabled;
         }
         return _loc2_;
      }
      
      private function parseVerifyUserData(param1:Object) : VerifyUserData {
         if(param1 == null)
         {
            return new VerifyUserData();
         }
         var _loc2_:VerifyUserData = new VerifyUserData();
         if(param1.hasOwnProperty("uid"))
         {
            _loc2_.uid = param1.uid;
         }
         if(param1.hasOwnProperty("nick_name"))
         {
            _loc2_.nick_name = param1.nick_name;
         }
         if(param1.hasOwnProperty("verified"))
         {
            _loc2_.verified = param1.verified;
         }
         if(param1.hasOwnProperty("verified_reason"))
         {
            _loc2_.verified_reason = param1.verified_reason;
         }
         if(param1.hasOwnProperty("verified_icon"))
         {
            _loc2_.verified_icon = param1.verified_icon;
         }
         if(param1.hasOwnProperty("avatar"))
         {
            _loc2_.avatar = param1.avatar;
         }
         if(param1.hasOwnProperty("home_url"))
         {
            _loc2_.home_url = param1.home_url;
         }
         if(param1.hasOwnProperty("followers_count"))
         {
            _loc2_.followers_count = param1.followers_count;
         }
         if(param1.hasOwnProperty("notes"))
         {
            _loc2_.notes = param1.notes;
         }
         _loc2_.isHaveData = true;
         return _loc2_;
      }
      
      private function parseShowData(param1:Object) : ShowData {
         if(param1 == null)
         {
            return null;
         }
         var _loc2_:ShowData = new ShowData();
         if(param1.hasOwnProperty("showid"))
         {
            _loc2_.showID = param1.showid;
         }
         if(param1.hasOwnProperty("showid_encode"))
         {
            _loc2_.showidEncode = param1.showid_encode;
         }
         if(param1.hasOwnProperty("paid"))
         {
            _loc2_.isVideoPaid = param1.paid;
         }
         if(param1.hasOwnProperty("show_paid"))
         {
            _loc2_.isShowPaid = param1.show_paid;
         }
         if(param1.hasOwnProperty("copyright"))
         {
            _loc2_.copyright = param1.copyright;
         }
         if(param1.hasOwnProperty("theaterid"))
         {
            _loc2_.theaterID = param1.theaterid;
         }
         if(param1.hasOwnProperty("show_videotype"))
         {
            _loc2_.showVideoType = param1.show_videotype;
         }
         if(param1.hasOwnProperty("stage"))
         {
            _loc2_.stage = param1.stage;
         }
         if(param1.hasOwnProperty("paid_url"))
         {
            _loc2_.paidURL = param1.paid_url;
         }
         return _loc2_;
      }
      
      public function parseProgramListData(param1:Object, param2:Object, param3:Object) : ProgramListData {
         var _loc5_:String = null;
         var _loc6_:Object = null;
         var _loc7_:IProgramData = null;
         var _loc4_:ProgramListData = new ProgramListData();
         _loc4_.videoList = new Array();
         if(param1 != null)
         {
            for(_loc5_ in param1)
            {
               _loc6_ = param1[_loc5_];
               _loc7_ = new ProgramData();
               _loc7_.title = _loc6_.title;
               _loc7_.playNumber = _loc6_.vv;
               _loc7_.videoID = _loc6_.vidEncoded;
               _loc7_.position = _loc6_.seq;
               _loc4_.videoList.push(_loc7_);
            }
         }
         _loc4_.preVideo = param2;
         if(param2 == null || !param2.hasOwnProperty("vidEncoded"))
         {
            _loc4_.preVideo = null;
         }
         _loc4_.nextVideo = param3;
         if(param3 == null || !param3.hasOwnProperty("vidEncoded"))
         {
            _loc4_.nextVideo = null;
         }
         return _loc4_;
      }
      
      private function pareseTrialData(param1:Object) : TrialData {
         if(param1 == null)
         {
            return null;
         }
         var _loc2_:TrialData = new TrialData();
         if(param1.hasOwnProperty("type"))
         {
            _loc2_.type = param1.type;
         }
         if(param1.hasOwnProperty("time"))
         {
            _loc2_.time = int(param1.time);
         }
         if(param1.hasOwnProperty("episodes"))
         {
            _loc2_.episodes = int(param1.episodes);
         }
         if(_loc2_.type == "episodes")
         {
            _loc2_.endTime = -1;
         }
         else if(_loc2_.type == "time")
         {
            _loc2_.endTime = _loc2_.time;
         }
         else if(_loc2_.type == "cannot")
         {
            _loc2_.endTime = 0;
         }
         
         
         return _loc2_;
      }
      
      private function parseCaptionData(param1:Object) : CaptionData {
         var _loc6_:Object = null;
         if(param1 == null || param1.attachment == null)
         {
            return null;
         }
         if(param1.attachment.length <= 0)
         {
            return null;
         }
         var _loc2_:* = false;
         var _loc3_:int = param1.attachment.length;
         var _loc4_:* = 0;
         while(_loc4_ < _loc3_)
         {
            _loc6_ = param1.attachment[_loc4_] as Object;
            if(_loc6_.type == "subtitle")
            {
               _loc2_ = true;
            }
            _loc4_++;
         }
         if(!_loc2_)
         {
            return null;
         }
         var _loc5_:CaptionData = new CaptionData();
         return _loc5_;
      }
      
      private function parseThreeDData(param1:Object) : ThreeDData {
         if(param1 == null || param1.threed == null)
         {
            return null;
         }
         var _loc2_:ThreeDData = new ThreeDData();
         if(param1.threed.type == "TB")
         {
            _loc2_.direct = "v";
         }
         else
         {
            _loc2_.direct = "h";
         }
         return _loc2_;
      }
      
      private function parseDVDData(param1:Object) : DVDData {
         var _loc3_:String = null;
         var _loc4_:InsertPointData = null;
         var _loc5_:Object = null;
         if(param1 == null)
         {
            return new DVDData();
         }
         var _loc2_:DVDData = new DVDData();
         if(param1.hasOwnProperty("ctype"))
         {
            _loc2_.ctype = param1.ctype;
         }
         if(param1.hasOwnProperty("state"))
         {
            _loc2_.state = param1.state;
         }
         if(param1.hasOwnProperty("head"))
         {
            _loc2_.headPostion = int(param1.head);
         }
         if(param1.hasOwnProperty("tail"))
         {
            _loc2_.tailPostion = int(param1.tail);
         }
         if(param1.hasOwnProperty("files"))
         {
            _loc2_.files = this.parseDVDFiles(param1.files);
         }
         if(param1.hasOwnProperty("point"))
         {
            _loc2_.insertPoints = [];
            for(_loc3_ in param1.point)
            {
               _loc4_ = new InsertPointData();
               if(param1.point[_loc3_].hasOwnProperty("start"))
               {
                  _loc4_.startTime = int(param1.point[_loc3_].start);
               }
               if(param1.point[_loc3_].hasOwnProperty("ctype"))
               {
                  _loc4_.ctype = param1.point[_loc3_].ctype;
               }
               if(param1.point[_loc3_].hasOwnProperty("title"))
               {
                  _loc4_.title = param1.point[_loc3_].title;
               }
               if(param1.point[_loc3_].hasOwnProperty("desc"))
               {
                  _loc4_.desc = param1.point[_loc3_].desc;
               }
               _loc2_.insertPoints.push(_loc4_);
            }
         }
         if(param1.hasOwnProperty("notsharing"))
         {
            _loc2_.notsharing = int(param1.notsharing);
         }
         if(param1.hasOwnProperty("audiolang"))
         {
            _loc2_.audioLangs = new Array();
            for(_loc3_ in param1.audiolang)
            {
               _loc5_ = {};
               if(param1.audiolang[_loc3_].hasOwnProperty("lang"))
               {
                  _loc5_.lang = param1.audiolang[_loc3_].lang;
               }
               if(param1.audiolang[_loc3_].hasOwnProperty("langid"))
               {
                  _loc5_.langid = param1.audiolang[_loc3_].langid;
               }
               if(param1.audiolang[_loc3_].hasOwnProperty("vid"))
               {
                  _loc5_.vid = param1.audiolang[_loc3_].vid;
               }
               _loc2_.audioLangs.push(_loc5_);
            }
         }
         if(_loc2_.headPostion == 0)
         {
            _loc2_.headPostion = -1;
         }
         if(_loc2_.tailPostion == 0)
         {
            _loc2_.tailPostion = -1;
         }
         return _loc2_;
      }
      
      private function parseDVDFiles(param1:Object) : Array {
         return [];
      }
      
      private function parsePreviews(param1:Object) : Array {
         var _loc6_:String = null;
         if(param1 == null || param1.thumbs == null || param1.host == null)
         {
            return null;
         }
         var _loc2_:Array = param1.thumbs as Array;
         var _loc3_:Array = new Array();
         var _loc4_:String = param1.host as String;
         var _loc5_:* = 0;
         while(_loc5_ < _loc2_.length)
         {
            _loc6_ = _loc4_ + String(_loc2_[_loc5_]);
            _loc3_.push(_loc6_);
            _loc5_++;
         }
         return _loc3_;
      }
   }
}
